<extend name="./public/frame.html"/>
<block name="content">
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/lang/zh-cn/zh-cn.js"></script>
    <style>
        #editor{width:1220px;}
    </style>
    <form class="layui-form layui-form-pane1" action="" method="post">
        <table class="layui-table">
            <tr>
                <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                    <input type="text" class="layui-input" readonly value="充值入口广告位" style="border: 0px;width: 12%;float:left;background:#F8F8F8">
                    <input type="checkbox" data-type="advert_one" lay-skin="switch" lay-filter="switchCheck" class="check" lay-text="开启|关闭" value="0" <?php if($result['recharge_homepage_display'] == 0):?>checked<?php endif;?>>
                    <input type="hidden" name="recharge_homepage_display" id="recharge_homepage_display" value="<?php echo $result['recharge_homepage_display'];?>" >
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">广告banner</td>
                <td>
                    <img id="prcUrl_1" layer-src="<?php echo $result['recharge_homepage_url'];?>" src="<?php echo $result['recharge_homepage_url'];?>" width="100px;" height="100px;" <?php if(empty($result['recharge_homepage_url'])):?>style="display: none;"<?php endif;?>>
                    &nbsp;&nbsp;
                    <button type="button" class="layui-btn uploadPhoto_1"><i class="layui-icon">&#xe67c;</i>上传图片</button>
                    <input name="recharge_homepage_url" id="recharge_homepage_url" type="hidden" value="<?php echo $result['recharge_homepage_url'];?>">
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">链接地址</td>
                <td>
                    <input type="text" name="recharge_homepage_jump_url" id="recharge_homepage_jump_url" value="<?php echo $result['recharge_homepage_jump_url'];?>" class="layui-input" style="width: 500px;">
                </td>
            </tr>
        </table>
        <table class="layui-table">
            <tr>
                <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                    <input type="text" class="layui-input" readonly value="充值消息" style="border: 0px;width: 12%;float:left;background:#F8F8F8">
                    <input type="checkbox" data-type="advert_two" lay-skin="switch" lay-filter="switchCheck" class="check" lay-text="开启|关闭" value="0" <?php if($result['recharge_homepage_display'] == 0):?>checked<?php endif;?>>
                    <input type="hidden" name="recharge_msg" id="recharge_msg" value="<?php echo $result['recharge_msg'];?>" >
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">消息内容</td>
                <td>
                    <textarea rows="3" class="layui-textarea" name="recharge_message" id="recharge_message"  maxlength="80" placeholder="请输入充值消息" style="width: 500px;"><?php echo $result['recharge_message'];?></textarea>
                </td>
            </tr>
        </table>
        <table class="layui-table">
            <tr>
                <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                    <input type="text" class="layui-input" readonly value="充值首页广告位" style="border: 0px;width: 12%;float:left;background:#F8F8F8">
                    <input type="checkbox" data-type="advert_three" lay-skin="switch" lay-filter="switchCheck" class="check" checked lay-text="开启|关闭" value="0" >
                    <input type="hidden" name="recharge_display" id="recharge_display" value="<?php echo $result['recharge_display'];?>" >
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">广告banner</td>
                <td>
                    <img id="prcUrl_2" layer-src="<?php echo $result['recharge_url'];?>" src="<?php echo $result['recharge_url'];?>" width="100px;" height="100px;" <?php if(empty($result['recharge_url'])):?>style="display: none;"<?php endif;?>>
                    &nbsp;&nbsp;
                    <button type="button" class="layui-btn uploadPhoto_2">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input name="recharge_url" id="recharge_url" type="hidden" value="<?php echo $result['recharge_url'];?>">
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">链接地址</td>
                <td>
                    <input type="text" name="recharge_jump_url" id="recharge_jump_url" value="<?php echo $result['recharge_jump_url'];?>" class="layui-input" style="width: 500px;">
                </td>
            </tr>
        </table>
        <table class="layui-table">
            <tr>
                <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                    <input type="text" class="layui-input" readonly value="充值成功广告位" style="border: 0px;width: 12%;float:left;background:#F8F8F8">
                    <input type="checkbox" data-type="advert_four" lay-skin="switch" lay-filter="switchCheck" class="check" lay-text="开启|关闭" value="0" <?php if($result['recharge_homepage_display'] == 0):?>checked<?php endif;?>>
                    <input type="hidden" name="recharge_success_display" id="recharge_success_display" value="<?php echo $result['recharge_success_display'];?>" >
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">广告banner</td>
                <td>
                    <img id="prcUrl_3" layer-src="<?php echo $result['recharge_success_url'];?>" src="<?php echo $result['recharge_success_url'];?>" width="100px;" height="100px;" <?php if(empty($result['recharge_success_url'])):?>style="display: none;"<?php endif;?>>
                    &nbsp;&nbsp;
                    <button type="button" class="layui-btn uploadPhoto_3">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input name="recharge_success_url" id="recharge_success_url" type="hidden" value="<?php echo $result['recharge_success_url'];?>">
                </td>
            </tr>
            <tr>
                <td style="width: 10%;text-align: center;">链接地址</td>
                <td>
                    <input type="text" name="recharge_success_jump_url" id="recharge_success_jump_url" value="<?php echo $result['recharge_success_jump_url'];?>" class="layui-input" style="width: 500px;">
                </td>
            </tr>
        </table>
        <table class="layui-table" style="height: auto;">
            <tr>
                <td style="font-weight: bold;color: black; background:#F8F8F8" colspan="2">
                    <input type="text" class="layui-input" readonly value="充值协议" style="border: 0px;width: 12%;background:#F8F8F8">
                </td>
            </tr>
            <tr>
                <td>
                    <script type="text/plain" name="recharge_agreement" id="editor"><?php echo $result['recharge_agreement']?></script>
                </td>
            </tr>
        </table>
        <table class="layui-table">
            <tr>
                <td colspan="3" style="padding-left: 100px;">
                    <input type="hidden" value="<?php echo $result['activity_id']?>" id="activity_id" name="activity_id">
                    <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form', 'upload'], function(){
            var form = layui.form,upload = layui.upload;
            //上传图片 - 充值入口banner
            upload.render({
                elem: '.uploadPhoto_1'//这个就等同于点击
                , url: '/admin/Upload/uploadImg'
                , done: function (res) { //上传后的回调
                    console.log(res)
                    if (res.status == 1) {
                        $("#prcUrl_1").css('display', '');
                        $("#prcUrl_1").attr('src', res.data.file); //点击后的大图
                        $("#prcUrl_1").attr('layer-src', res.data.file_thumb); //小图
                        $("#recharge_homepage_url").val(res.data.file); //点击后的大图
                        layer.msg('上传成功', {icon: 1});
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function (e) {
                    console.log(e)
                }
            });
            //上传图片 - 充值首页广告位
            upload.render({
                elem: '.uploadPhoto_2'//这个就等同于点击
                , url: '/admin/Upload/uploadImg'
                , done: function (res) { //上传后的回调
                    console.log(res)
                    if (res.status == 1) {
                        $("#prcUrl_2").css('display', '');
                        $("#prcUrl_2").attr('src', res.data.file); //点击后的大图
                        $("#prcUrl_2").attr('layer-src', res.data.file_thumb); //小图
                        $("#recharge_url").val(res.data.file); //点击后的大图
                        layer.msg('上传成功', {icon: 1});
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function (e) {
                    console.log(e)
                }
            });
            //上传图片 - 充值成功广告位
            upload.render({
                elem: '.uploadPhoto_3'//这个就等同于点击
                , url: '/admin/Upload/uploadImg'
                , done: function (res) { //上传后的回调
                    if (res.status == 1) {
                        $("#prcUrl_3").css('display', '');
                        $("#prcUrl_3").attr('src', res.data.file); //点击后的大图
                        $("#prcUrl_3").attr('layer-src', res.data.file_thumb); //小图
                        $("#recharge_success_url").val(res.data.file); //点击后的大图
                        layer.msg('上传成功', {icon: 1});
                    } else {
                        layer.msg(res.msg);
                    }
                }
                , error: function (e) {
                    console.log(e)
                }
            });
            //入口 - 开启/关闭操作
            form.on('switch(switchCheck)', function(data){
                if(!this.checked){
                    var value = 0;
                }else{
                    var value = 1;
                }
                var key_name = $(this).data('type');
                if(key_name == 'advert_one'){                       //充值入口
                    if(value == 1){
                        $('#recharge_homepage_display').val(0);
                    }else{
                        $('#recharge_homepage_display').val(1);
                    }
                }else if(key_name == 'advert_two'){                 //充值消息
                    if(value == 1){
                        $('#recharge_msg').val(0);
                    }else{
                        $('#recharge_msg').val(1);
                    }
                }else if(key_name == 'advert_three'){               //充值首页广告位
                    if(value == 1){
                        $('#recharge_display').val(0);
                    }else{
                        $('#recharge_display').val(1);
                    }
                }else if(key_name == 'advert_four'){                //充值成功广告位
                    if(value == 1){
                        $('#recharge_success_display').val(0);
                    }else{
                        $('#recharge_success_display').val(1);
                    }
                }
            });
            //活动配置数据提交
            form.on('submit(*)', function (data) {
                $.ajax({
                    url:'{:url("/admin/Promotion/activity")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data: $(data.form).serialize(),
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;

            })
        });
    </script>
    <script type="text/javascript">
        var ue = UE.getEditor('editor',{
            zIndex : 0,
        });
    </script>
</block>
